var userList = [];
var app = new Vue({
    el: '#app',
    data: {
        visible: false,
        //搜索
        formInline: {
            name: ''
        },
        //列表
        activeName: 'first',
        userList: userList,
        //分页
        currentPage: 1,
        pageSize: 2,
        pageTotal: 2,
        //查看
        dialogUserInfo: false,
        userInfo: [{
            id: 0,
            name: '',
            email: '',
            updated_at: '',
        }],
        //编辑
        dialogUserEdit: false,
        form: {},
        formLabelWidth: '150px',
        //删除
        dialogUserDelete: false
    },
    methods: {
        onSubmit: function () {
            //获取当前页码
            this.getUserList(this.currentPage, app.formInline);
        },
        handleSizeChange: function (val) {
            console.log('每页' + val + '条');
        },
        handleCurrentChange: function (val) {
            //this.currentPage = val;
            //console.log('当前页: ' + val);
            this.getUserList(val, []);
        },
        handleView: function (index, row) {
            this.getOneUserInfo(row.id);
            this.$data.dialogUserInfo = true;
        },
        handleEdit: function (index, row) {
            this.getOneUserInfo(row.id);
            this.$data.dialogUserEdit = true;
        },
        dialogUserEditAAA: function () {
            this.$data.dialogUserEdit = false;
            this.$message('编辑成功');
        },
        handleDelete: function (index, row) {
            this.$data.dialogUserDelete = true;
        },
        dialogVisible: function (index, row) {
            console.log(index, row);
        },
        getOneUserInfo: function (userId) {
            /**
             *获取单个会员信息
             **/
            $.ajax({
                url: '/admin/user/getOne',
                dataType: 'json',
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                data: {
                    userId: userId
                },
                success: function (data, textStatus, jqXHR) {
                    console.log(data);
                    var userInfo = data.datas;
                    app.userInfo = userInfo;
                    //this.$data.userInfo.id = userInfo.id;
                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                }
            });
        },
        //获取会员列表
        getUserList: function (currentPage, formData) {
            console.log(formData);
            $.ajax({
                url: '/admin/user/list',
                dataType: 'json',
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                data: {
                    page: currentPage,
                    name: formData ? formData.name : ''
                },
                success: function (data, textStatus, jqXHR) {
                    console.log(data);
                    //填充数据
                    app.userList = data.datas.data;
                    //填充分页
                    app.currentPage = data.datas.current_page;
                    app.pageTotal = data.datas.total;
                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                }
            });
        }
    }
});
app.getUserList(1);
